<template>
  <div id="postUserInfo">
    <div class="img-list-box">
      <!--展示图片-->
      <showImg :img-list="item.content.img"></showImg>
    </div>
    <div class="info-right">
      <div class="right-top">
        <dl class="info-header">
          <dt>
            <el-image :src="item.user.avatar" fit="avatar"></el-image>
          </dt>
          <dd>
            <span class="nike-name">
              {{ item.user.name }}
              <!--活动分类-->
              {{ item.tags.activityCategory | filterName('tagsType') }}
              <!--活动名称-->
              {{ item.category.activityName }}
              <template v-if="item.category.state === 'DELETE'"
                >(已删除)</template
              >
            </span>
            <!--马甲 \ 用户-->
            <el-tag type="success" effect="dark">
              {{ item.userProperty | filterName('userProperty') }}
            </el-tag>
            <!--此处插槽，用来添加其他tag标签-->
            <slot name="infoTag"></slot>
            <el-popover
              v-if="showUp"
              v-model="visible"
              placement="bottom"
              width="180"
              trigger="manual"
            >
              <p class="pop-con" v-html="upCon"></p>
              <el-button slot="reference" @click="addPraiseSpeed('1')">
                加赞进度
              </el-button>
            </el-popover>
            <el-popover
              v-if="showUpTimeIng"
              v-model="visibleTimeIng"
              placement="bottom"
              width="180"
              trigger="manual"
            >
              <p class="pop-con" v-html="upContentIng"></p>
              <el-button slot="reference" @click="addPraiseSpeed('2')">
                限时批量加赞中
              </el-button>
            </el-popover>
            <el-popover
              v-if="showUpTime"
              v-model="visibleTime"
              placement="bottom"
              width="250"
              trigger="manual"
            >
              <p class="pop-con" v-html="upContent"></p>
              <!-- <el-button slot="reference" @click="addPraiseSpeed('3')">
                限时批量加赞
              </el-button> -->
            </el-popover>
          </dd>
          <dd>
            <span class="nick-code">{{ item.user.dpAccount }}</span>
            <span class="nick-code"
              >活动帖子发布时间：{{ item.createdDate | timeToTime }}</span
            >
          </dd>
        </dl>
        <div class="info-content">
          <span v-html="filterContent(item.content.text)"></span>
        </div>
      </div>
      <ul class="foot-list">
        <!-- v-if=" powerAry.includes( `system:${from === 'postMine' ? 'myPosts' :
        'posts'}:comment` ) " -->
        <li
          v-permission="
            `wh:system:${from === 'postMine' ? 'myPosts' : 'posts'}:comment`
          "
          class="pointer"
          @click="
            changeView(
              from === 'postMine'
                ? 'wh:system:postMine:postCommentList'
                : 'wh:system:posts:postCommentList'
            )
          "
        >
          评论 {{ item.commentCount }}
        </li>
        <!-- v-if=" powerAry.includes( `system:${from === 'postMine' ? 'myPosts' :
        'posts'}:praise` ) " -->
        <li
          v-permission="
            `wh:system:${from === 'postMine' ? 'myPosts' : 'posts'}:praise`
          "
          class="pointer"
          @click="
            changeView(
              from === 'postMine'
                ? 'wh:system:postMine:postUpList'
                : 'wh:system:posts:postUpList'
            )
          "
        >
          点赞 {{ item.likeCount }}
        </li>
        <!-- v-if=" powerAry.includes( `system:${from === 'postMine' ? 'myPosts' :
        'posts'}:share` ) " -->
        <li
          v-permission="
            `wh:system:${from === 'postMine' ? 'myPosts' : 'posts'}:share`
          "
          class="pointer"
          @click="showDialogNum('share')"
        >
          虚拟分享量 {{ item.shareCount.sham }}
        </li>
        <li>真实分享量 {{ item.shareCount.real }}</li>
        <li class="canClick" @click="getEditor">最新编辑者 {{ editor }}</li>
        <li v-if="item.deleted">删除理由： {{ item.reason }}</li>
      </ul>
      <!--隐性标签-->
      <hideLabel
        v-permission="
          `wh:system:${from === 'postMine' ? 'myPosts' : 'posts'}:label`
        "
        :hideLabelObj="hideLabelObj"
        :user="item.user"
        :labels="item.labels"
        :labelList="labelList"
        :labelListTotal="labelListTotal"
        v-if="showHideLabel"
      ></hideLabel>
    </div>
    <dialogNum
      v-if="dialogNumData.isShow"
      :dialog-data="dialogNumData"
      @changeNum="changeNum"
    ></dialogNum>
  </div>
</template>

<script>
import { editor, changeShare } from '@/api/activeManagement/post' // 接口
import { contentToStr } from '@utils/pubFunction'
import showImg from '@common/showImg'
import dialogNum from '@common/dialogNum' // 虚拟分享量/虚拟播放量-弹窗
import hideLabel from '@common/hideLabel/index' //  隐性标签
import { praiseSpeed } from '@/api/common/likesAPI'
export default {
  name: 'PostUserInfo',
  msg: '动态管理-动态维护-用户主要信息',
  props: ['item', 'index', 'from', 'powerAry', 'labelList', 'labelListTotal'], // from-"postMine"(我的发布)/"postPre"(动态维护)
  data() {
    return {
      categoryType: 2, // 1.社团 2.活动 3.作品 4.作业 5.回放视频 8.生活
      editor: '', // 最新编辑者
      dialogData: {
        isShow: false, // 默认隐藏
        params: '' // 编辑时，传递的参数
      },
      dialogNumData: {
        // 虚拟分享量/虚拟播放量
        isShow: false, // 默认隐藏
        type: '',
        num: 0,
        params: '' // 编辑时，传递的参数
      },
      upCon: '', // 加赞进度
      upContentIng: '', // 限时批量加赞中
      upContent: '', // 限时批量加赞
      visible: false, // 激活显示内容-加赞进度
      visibleTimeIng: false, // 激活显示内容-限时批量加赞中
      visibleTime: false, // 激活显示内容-限时批量加赞
      showUp: false, // 是否显示加赞进度
      showUpTimeIng: false, // 是否显示限时批量加赞中
      showUpTime: false, // 是否显示限时批量加赞
      showHideLabel: false, //是否显示隐性标签
      hideLabelObj: {} //是否显示隐性标签
    }
  },
  computed: {
    listenshowUp() {
      return this.$store.state.praiseSpeed[`post_${this.from}_up_${this.index}`]
    },
    listenshowUpTime() {
      return this.$store.state.praiseSpeed[
        `post_${this.from}_UpTime_${this.index}`
      ]
    }
  },
  watch: {
    listenshowUp(newV, oldV) {
      if (newV) {
        this.showUp = true
      } else {
        this.showUp = false
      }
    },
    listenshowUpTime(newV, oldV) {
      if (newV) {
        this.showUpTime = true
      } else {
        this.showUpTime = false
      }
    }
  },
  mounted() {
    this.setShowUpBtn()
    this.getLabelShowStatu()
  },
  methods: {
    /* 过滤返回内容 */
    filterContent(item) {
      return contentToStr(item)
    },
    /*隐性标签是否显示*/
    getLabelShowStatu() {
      let isShow = !this.item.deleted
      // let power = this.powerAry.includes(
      //   `system:${this.from === 'postMine' ? 'myPosts' : 'posts'}:label`
      // )
      // this.showHideLabel = isShow && power
      this.showHideLabel = isShow
      if (this.showHideLabel) {
        //整合obj
        let {
          category: { id: activityId },
          labelManualResult: auditStatu,
          content: { text: content },
          id: contentId,
          createdDate: createDate,
          content: { img },
          operationId: operatorId,
          userProperty: userProperty,
          user: { id: userId }
        } = this.item
        let images = img ? img.join(',') : ''
        this.hideLabelObj = {
          activityId, //活动id
          auditStatu, //人审状态 PASS通过 / UNCHECKED未审核
          collegeId: '', //学院id
          content, //内容
          contentId, //内容id
          createDate, //创建时间
          displayRule: '', //展示规则 ALL公开展示 / PERSONAL仅主页可见
          images, //图片
          type: 'TEXT', //内容类型：图文/视频,可用值:TEXT,VIDEO
          operatorId, //运营人id
          userProperty: userProperty === 'VESTUSER' ? 'VEST' : userProperty, //马甲、用户,可用值:REALUSER,VEST
          userId, //发帖人id
          videoId: '', //保利威视vid
          channel: 'ACTIVITY_POST' //频道,可用值:JOB,LIFE,WORK,GROW,ACTIVITY,ARTICLE,SHORT_VIDEO,LONG_VIDEO
        }
        /*console.log(this.hideLabelObj)*/
      }
    },
    /* 判断加赞按钮显示隐藏 */
    setShowUpBtn() {
      if (this.item.robotPraise != null) {
        // 普通点赞状态
        if (this.item.robotPraise.taskList != null) {
          if (this.item.robotPraise.taskList.length > 0) {
            // 加赞进度
            this.showUp = true // 加赞进度
          }
        }
        if (
          this.item.robotPraise.executionTask != null ||
          this.item.robotPraise.unExecutionTask != null
        ) {
          if (this.item.robotPraise.executionTask.length > 0) {
            // 限时批量加赞中
            this.showUpTimeIng = true // 限时批量加赞中
          } else if (this.item.robotPraise.unExecutionTask.length > 0) {
            // 限时批量加赞
            this.showUpTime = true // 限时批量加赞
          }
        }
      }
    },
    /* 显示加赞进度 */
    async addPraiseSpeed(type) {
      let obj = {
        topicId: this.item.id,
        topicCreatedBy: this.item.user.id,
        categoryType: this.categoryType
      }
      let data = await praiseSpeed(obj)
      switch (type) {
        case '1': // 加赞进度
          this.showUpCon(data.taskList, 'visible', 'upCon', '')
          break
        case '2': // 限时批量加赞中
          this.showUpCon(
            data.executionTask,
            'visibleTimeIng',
            'upContentIng',
            ''
          )
          break
        case '3': // 限时批量加赞
          this.showUpCon(
            data.unExecutionTask,
            'visibleTime',
            'upContent',
            'addDate'
          )
          break
      }
    },
    /* 设置当前显示点赞内容 */
    showUpCon(targetDate, targetVisible, targetCon, type = '') {
      let _this = this
      _this[targetCon] = ''
      this[targetVisible] = true
      let curData = targetDate
      if (curData.length > 0) {
        curData.forEach((item, index) => {
          if (index > 0) {
            _this[targetCon] += `<br/>`
          }
          _this[
            targetCon
          ] += `${item.number}/${item.total}  ${item.operateUser.nickName}`
          if (type) {
            _this[targetCon] += `--- ${item.startDate}`
          }
        })
      } else {
        _this[targetCon] = '暂无加赞进度'
      }
      setTimeout(() => {
        this[targetVisible] = false
      }, 2000)
    },
    /* 获取最新编辑者 */
    getEditor() {
      editor(this.item.id, (response) => {
        let e = response || ' -'
        this.editor = ':' + e
      })
    },
    /* 显示-虚拟分享量/虚拟播放量-弹窗 */
    showDialogNum(type) {
      if (this.item.deleted) return
      this.dialogNumData.type = type
      this.dialogNumData.isShow = true
    },
    /* 跳转页面 */
    changeView(name) {
      let id = this.item.id
      let from = this.from
      let query = {
        from,
        id
      }
      this.$router.push({ name, query })
    },
    /*关闭虚拟分享量/播放量弹窗*/
    closeDialog() {
      this.dialogNumData.isShow = false
      this.dialogNumData.type = ''
    },
    /* 修改虚拟分享量 */
    changeNum(n) {
      let obj = {
        shareCount: n
      }
      changeShare(
        this.item.id,
        obj,
        (response) => {
          this.$message.success('操作成功')
          this.closeDialog()
          this.item.shareCount.sham = n
          /*this.$emit('refresh')*/
        },
        (response) => {
          this.$message.warning(response.message)
        }
      )
    }
  },
  components: {
    showImg,
    dialogNum,
    hideLabel
  }
}
</script>

<style lang="less">
#postUserInfo {
  display: flex;
  justify-content: left;
  @import url('~@common/style/userInfo.less');
}
</style>
